package com.ruoyi.web.controller.system;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.vo.Characters;
import com.ruoyi.system.service.ICharactersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 角色Controller
 *
 * @author ruoyi
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/system/characters")
public class CharactersController extends BaseController
{
    @Autowired
    private ICharactersService charactersService;

    /**
     * 查询角色列表
     */
    @PreAuthorize("@ss.hasPermi('system:characters:list')")
    @PostMapping("/list")
    public TableDataInfo list(@Param("characters") Characters characters)
    {
        startPage();
        List<Characters> list = charactersService.selectCharactersList(characters);
        return getDataTable(list);
    }

    /**
     * 导出角色列表
     */
    @PreAuthorize("@ss.hasPermi('system:characters:export')")
    @Log(title = "角色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Characters characters)
    {
        List<Characters> list = charactersService.selectCharactersList(characters);
        ExcelUtil<Characters> util = new ExcelUtil<Characters>(Characters.class);
        util.exportExcel(response, list, "角色数据");
    }

    /**
     * 获取角色详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:characters:query')")
    @GetMapping(value = "/{charactersId}")
    public AjaxResult getInfo(@PathVariable("charactersId") Long charactersId)
    {
        return success(charactersService.selectCharactersByCharactersId(charactersId));
    }

    /**
     * 新增角色
     */
    @PreAuthorize("@ss.hasPermi('system:characters:add')")
    @Log(title = "角色", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody Characters characters)
    {
        return toAjax(charactersService.insertCharacters(characters));
    }

    /**
     * 修改角色
     */
    @PreAuthorize("@ss.hasPermi('system:characters:edit')")
    @Log(title = "角色", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody Characters characters)
    {
        return toAjax(charactersService.updateCharacters(characters));
    }

    /**
     * 删除角色
     */
//    @PreAuthorize("@ss.hasPermi('system:characters:remove')")
//    @Log(title = "角色", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{charactersId}")
//    public AjaxResult removes(@PathVariable Long charactersId)
//    {
//        return toAjax(charactersService.deleteCharactersByCharactersIds(charactersId));
//    }

    /**
     * 删除角色信息
     */
    @PreAuthorize("@ss.hasPermi('system:characters:remove')")
    @Log(title = "角色", businessType = BusinessType.DELETE)
    @DeleteMapping("delete/{charactersId}")
    public AjaxResult remove(@PathVariable Long charactersId)
    {
        return toAjax(charactersService.deleteCharactersByCharactersId(charactersId));
    }
}